<!DOCTYPE html>
<html>

<head>
  <title>
    <%= title %>
  </title>
  <link rel='stylesheet' href='/lib/bootstrap/dist/css/bootstrap.min.css' />
  <link rel='stylesheet' href='/stylesheets/font-awesome.min.css' />
  <link rel='stylesheet' href='/stylesheets/ionicons.min.css' />
  <link rel='stylesheet' href='/lib/admin-lte/dist/css/AdminLTE.css' />
  <link rel='stylesheet' href='/lib/admin-lte/dist/css/skins/skin-blue.min.css' />
  <link rel='stylesheet' href='/stylesheets/style.css' />

</head>

<body class="hold-transition skin-blue sidebar-mini">
  <div class="wrapper">

    <!-- 头部 -->
    <% include header.ejs%>
      <!-- Left side column. contains the logo and sidebar -->
      <!-- 左侧栏 -->
      <% include menu.ejs%>
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
          <!-- Content Header (Page header) -->


          <!-- Main content -->
          <section class="content">

            <!-- Your Page Content Here -->
            <!-- <% for(var i =0;i<3;i++){ %>
              <h3>aaa</h3>

            <% } %> -->
            <div class="box">
              <div class="box-header with-border">
                <h3 class="box-title">
                  电影列表
                  <button class="btn btn-sm btn-success">
                    <span class="glyphicon glyphicon-plus" onclick="toAddMovie()"></span>添加
                  </button>
                </h3>
                <button class="btn btn-sm btn-default pull-right">
                  <span class="glyphicon glyphicon-plus"></span>导入数据
                </button>
                <button class="btn btn-sm btn-info pull-right">
                  <span class="glyphicon glyphicon-plus"></span>导出数据
                </button>
              </div>
              <!-- /.box-header -->
              <div class="box-body">
                <table class="table table-bordered">
                  <tr>
                    <th style="width: 10px">#</th>
                    <th>名称/年份</th>
                    <th>图片</th>
                    <th onclick="sortByRating()">
                      评分
                    <% if (sort == 1) { %> 
                        <span id="ratingsort" class="glyphicon glyphicon-chevron-up pull-right"></span>
                    <% }else if (sort == -1){ %> 
                        <span id="ratingsort" class="glyphicon glyphicon-chevron-down pull-right"></span>
                     <% }else{ %>
                      <span class="glyphicon glyphicon-resize-vertical pull-right"></span>
                   <%  } %>
                     
                    </th>
                    <th>类型</th>
                    <th>操作</th>
                  </tr>

                  <% for(var i = 0; i< result.length;i++){  %>
                    <tr>
                      <td>
                        <%= i+1 %>
                      </td>
                      <td>
                        <%= result[i].title %>
                          -
                          <%= result[i].year %>
                      </td>
                      <td>
                        <img src="<%- result[i].images_small %>" style="width:60px" alt="">
                      </td>
                      <td>
                        <%= result[i].rating %>
                      </td>
                      <td>
                        <%= result[i].genres %>
                      </td>
                      <td>
                        <button class="btn btn-xs btn-warning" onclick="updateMovie(<%- result[i].id %>)">
                          <span class="glyphicon glyphicon-pencil"></span>编辑</button>
                        <button class="btn btn-xs btn-danger" onclick="deleteMovie(<%- result[i].id %>)">
                          <span class="glyphicon glyphicon-trash"></span>删除</button>
                      </td>
                    </tr>
                    <%  }  %>

                </table>
              </div>
              <!-- /.box-body -->
              <div class="box-footer clearfix">
                <ul class="pagination pagination-sm no-margin pull-left">
                  <li>总条数为:<%= allNum %></li>
                  <!-- <li>当前页数:<%= pageCode*1 +1 %></li> -->
                </ul>
                <ul class="pager">
                  <li><a href="#" onclick="toPage('prev',<%= totalPages %>)">上一页</a></li>
                  <li>
                    <input type="number" step="1" min="1" id="num" onchange="toPageNumFn()" max="<%= totalPages %>" value="<%= pageCode*1 %>" style="width:50px"/> / <%= totalPages-1 %>
                  </li>
                  <li><a href="#" onclick="toPage('next',<%= totalPages %>)">下一页</a></li>
                </ul>
                <!-- <ul class="pagination pagination-sm no-margin pull-right">
                  <li>
                    <a href="/list/fenye?limitNum=4&pageCode=0">&laquo;</a>
                  </li>
               <%   for (var i = 0;i< totalPages;i++) { %>
                    <li class="<%= pageCode==i ? 'active' : '' %>">
                        <a href="/list/fenye?limitNum=4&pageCode=<%= i %>"><%= i+1 %></a>
                    </li>
               <%   } %>
                  <li >
                    <a href="/list/fenye?limitNum=4&pageCode=<%= totalPages*1-1 %>">&raquo;</a>
                  </li>
                </ul> -->
              </div>
            </div>
          </section>
          <!-- /.content -->
        </div>
        <!-- /.content-wrapper -->

        <!-- 底部 -->
        <% include footer.ejs%>

          <!-- Control Sidebar -->
          <aside class="control-sidebar control-sidebar-dark">
            <!-- Create the tabs -->
            <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
              <li class="active">
                <a href="#control-sidebar-home-tab" data-toggle="tab">
                  <i class="fa fa-home"></i>
                </a>
              </li>
              <li>
                <a href="#control-sidebar-settings-tab" data-toggle="tab">
                  <i class="fa fa-gears"></i>
                </a>
              </li>
            </ul>
            <!-- Tab panes -->
            <div class="tab-content">
              <!-- Home tab content -->
              <div class="tab-pane active" id="control-sidebar-home-tab">
                <h3 class="control-sidebar-heading">近期活动</h3>
                <ul class="control-sidebar-menu">
                  <li>
                    <a href="javascript::;">
                      <i class="menu-icon fa fa-birthday-cake bg-red"></i>

                      <div class="menu-info">
                        <h4 class="control-sidebar-subheading">Langdon 的生日</h4>

                        <p>Will be 23 on April 24th</p>
                      </div>
                    </a>
                  </li>
                </ul>
                <!-- /.control-sidebar-menu -->

                <h3 class="control-sidebar-heading"> 任务进度</h3>
                <ul class="control-sidebar-menu">
                  <li>
                    <a href="javascript::;">
                      <h4 class="control-sidebar-subheading">
                        自定义模板设计
                        <span class="pull-right-container">
                          <span class="label label-danger pull-right">70%</span>
                        </span>
                      </h4>

                      <div class="progress progress-xxs">
                        <div class="progress-bar progress-bar-danger" style="width: 70%"></div>
                      </div>
                    </a>
                  </li>
                </ul>
                <!-- /.control-sidebar-menu -->

              </div>
              <!-- /.tab-pane -->
              <!--  统计信息选项卡内容 -->
              <div class="tab-pane" id="control-sidebar-stats-tab"> 统计信息选项卡内容</div>
              <!-- /.tab-pane -->
              <!-- Settings tab content -->
              <div class="tab-pane" id="control-sidebar-settings-tab">
                <form method="post">
                  <h3 class="control-sidebar-heading">常规设置项</h3>

                  <div class="form-group">
                    <label class="control-sidebar-subheading">
                      报告面板用法
                      <input type="checkbox" class="pull-right" checked>
                    </label>

                    <p>
                      常规设置选项的相关信息
                    </p>
                  </div>
                  <!-- /.form-group -->
                </form>
              </div>
              <!-- /.tab-pane -->
            </div>
          </aside>
          <!-- /.control-sidebar -->
          <!-- Add the sidebar's background. This div must be placed
                 immediately after the control sidebar -->
          <div class="control-sidebar-bg"></div>
  </div>
  <!-- ./wrapper -->
</body>
<script src="/javascripts/jquery.min.js"></script>
<script src="/lib/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="/javascripts/app.min.js"></script>
<script>
  function updateMovie(id) {
    // console.log(id);
    window.location.href = "/list/updateMovie?id=" + id;
  };
  function deleteMovie(id) {
    // console.log(id);
    window.location.href = "/list/deleteMovie?id=" + id;
  };
  function toAddMovie() {
    window.location.href = "/list/addMovie";
  };
  function sortByRating() {
    if ($("#ratingsort").hasClass("glyphicon-chevron-down")) {
      // 从小到大
      $("#ratingsort").removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
      window.location.href = "/list/listSort?sortType=rating&type=1"
    } else {
      // 从大到小
      $("#ratingsort").removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
      window.location.href = "/list/listSort?sortType=rating&type=-1"
    }
  };
  function toPageNumFn() {
    var pageCode = $("#num").val();
    window.location.href = "/list/fenye?limitNum=4&pageCode=" + pageCode;
  };
  function toPage(type,totalPages) {
    var pageCode = $("#num").val();
    if (type == "next") {
      if(pageCode == totalPages -1) {
        pageCode = totalPages -1;
        return;
      }else {
        pageCode++;
      }
    }else {
      if (pageCode == 0) {
        pageCode = 0;
        return;
      }else {
        pageCode--;
      }
    }
    $("#num").val(pageCode)
    window.location.href = "/list/fenye?limitNum=4&pageCode=" + pageCode;
  }
</script>

</html>